package com.mdp.sms.tencent.client;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 腾讯云短信签名api调用 https://cloud.tencent.com/document/product/382/6040
 * @author lyk
 * @cdate 2019/9/17 15:19
 */
@Service("mdp.sms.utils.SmsSignApi")
public class SmsSignApi {
	@Value("${mdp.sms.appid:1}")
	int appid;
	@Value("${mdp.sms.app-secret:}")
	String appkey;
	static Log log = LogFactory.getLog(SmsSignApi.class);

	@Autowired
	private SmsTemplateApi smsTemplateApi;
	// 添加短信签名 POST请求
	public static final String addSmsSignApi = "https://yun.tim.qq.com/v5/tlssmssvr/add_sign?sdkappid=";
	// 修改短信签名 POST请求
	public static final String modifySignApi = "https://yun.tim.qq.com/v5/tlssmssvr/mod_sign?sdkappid=";
	// 删除短信签名 POST请求
	public static final String delSmsSignApi = "https://yun.tim.qq.com/v5/tlssmssvr/del_sign?sdkappid=";
	// 短信签名状态查询 POST请求
	public static final String getSmsSignApi = "https://yun.tim.qq.com/v5/tlssmssvr/get_sign?sdkappid=";

	public Map<String, Object> addSmsSign(Map<String, Object> data) {
		String finallyRequestURL = smsTemplateApi.addTimeAndSig(data, addSmsSignApi);
		return smsTemplateApi.sentPostRequest(finallyRequestURL, data);
	}

	public Map<String, Object> modifySmsSign(Map<String, Object> data) {
		String finallyRequestURL = smsTemplateApi.addTimeAndSig(data, modifySignApi);
		return smsTemplateApi.sentPostRequest(finallyRequestURL, data);
	}

	public Map<String, Object> delSmsSign(Map<String, Object> data) {
		String finallyRequestURL = smsTemplateApi.addTimeAndSig(data, delSmsSignApi);
		return smsTemplateApi.sentPostRequest(finallyRequestURL, data);
	}

	public Map<String, Object> getSmsSign(Map<String, Object> data) {
		String finallyRequestURL = smsTemplateApi.addTimeAndSig(data, getSmsSignApi);
		return smsTemplateApi.sentPostRequest(finallyRequestURL, data);
	}
}
